package com.liumingtai.demo03.web.controller;

import cn.hutool.core.util.StrUtil;
import com.liumingtai.demo03.api.HelloService;
import com.liumingtai.demo03.api.UploadService;
import lombok.extern.log4j.Log4j2;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/hello")
@Log4j2
public class HelloController {
    @Reference
    HelloService helloService;

    @Autowired
    UploadService uploadService;

    @GetMapping("/name01")
    public String func(@RequestParam String name) {
        return helloService.helloName(name);
    }

    @RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
    @ResponseBody
    public String uploadImage(@RequestParam(name = "file", required = true) MultipartFile file) throws IOException {
        log.info(StrUtil.format("file getInputStream ===> {}", file.getInputStream()));
        return uploadService.uploadImage(file.getOriginalFilename(), file.getInputStream());
    }

}
